CPU instructions (continued)

to convert instruction to binary:

I-type instrs. cont.

For the immediate values in I-type instructions, need to use 2's complement to specify negative immediate values. This means that the range for immediate values is [-2^{15}, 2^{15}] (the same as the range of a short int).

Therefore, you cannot fully load large values into the register - there are "load upper immediate" instructions that we use to fill the upper half of the register (this is NOT covered in this course)

J-type (jump) instructions

Example J-type instruction:

j label

J-type instruction structure:

XXXXXX|XXXXXXXXXXXXXXXXXXXXXXXXXX
opcode| target address

We are told that for jump instructions, the opcode is 2.

Addressing modes

26 bits is insufficient to address the entire range of RAM (we assume RAM is addressible using 32 bits), so we need to use tricks ("addressing modes")

Four different addressing modes we will cover:

Example with most of the addressing modes (just without register addressing, will see that later)

Convert the following mips code to binary, and put it at address 0x00400068, using big-endian bit direction.

Label1:
    bne $t1, $zero, Label2
    lw $t7, -2($s0)
    add $t7, $t7, $zero
    j Label1

Label2:
    ...

The instructions are translated as follows: